package com.swlz.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swlz.dao.MallTypeDAO;
import com.swlz.dto.MallProductSearch;
import com.swlz.entity.MallProduct;
import com.swlz.entity.MallType;
import com.swlz.service.MallProductService;
import com.swlz.service.MallTypeService;
import com.swlz.service.impl.MallProductServiceImpl;
import com.swlz.service.impl.MallTypeServiceImpl;

import cn.hutool.extra.servlet.ServletUtil;

/**
 * 
 * @author swlz
 *E-Mail:1826400751@qq.com
 *Date:2020-8-17
 *className:project-M
 */
@WebServlet("/search.let")
public class SearchServlet extends HttpServlet {
	private MallProductService mallProductService = new MallProductServiceImpl();
	private MallTypeService mallTypeService = new MallTypeServiceImpl();
	private MallTypeDAO dao=new MallTypeDAO();
	@Override
		public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		MallProductSearch search=new MallProductSearch();			
		ServletUtil.fillBean(request, search, true);
		try {
			List<MallType> type=dao.selectByModel(null, 0, 1000);
			request.setAttribute("type", type);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("p", mallProductService.page(search));
		request.setAttribute("search", search);			
		request.getRequestDispatcher("user/search.jsp").forward(request, response);
			
		}
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
		


}
